import store from '../store'
import myRequest from '@/request'

const init =function (){
		
	getUser()
}

//使用token换取user 并将其存在vuex中
export const tokenToUser=function(){		
	myRequest({
		url:'/user/getUserInfo',
		method:'get'
	}).then((res)=>{	
		var user= res.data.data
		store.commit('user/SET_USERINFO',user)
		console.log(store.state.user.user)
	})
}

const getUser=function(){
	
	try {
	  
		var token = uni.getStorageSync('token');
			
		if(token){
			 store.commit('user/SET_TOKEN',token)
			 tokenToUser() //使用token换取user 并将其存在vuex中
		}
		
		
		
	} catch (e) {
	    // error
		console.log(e)
	}
}




init()

